package org.rsbot.event.impl;

import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Point;
import org.rsbot.bot.Bot;
import org.rsbot.client.Client;
import org.rsbot.event.listeners.PaintListener;
import org.rsbot.script.methods.Calculations;
import org.rsbot.script.methods.Game;
import org.rsbot.script.methods.MethodContext;

public class DrawPlayers
  implements PaintListener
{
  private MethodContext ctx;

  public DrawPlayers(Bot paramBot)
  {
    this.ctx = paramBot.getMethodContext();
  }

  public void onRepaint(Graphics paramGraphics) {
    if (!this.ctx.game.isLoggedIn())
      return;
    org.rsbot.client.RSPlayer[] arrayOfRSPlayer1 = this.ctx.client.getRSPlayerArray();
    if (arrayOfRSPlayer1 == null)
      return;
    FontMetrics localFontMetrics = paramGraphics.getFontMetrics();
    for (org.rsbot.client.RSPlayer localRSPlayer : arrayOfRSPlayer1) {
      if (localRSPlayer == null) {
        continue;
      }
      org.rsbot.script.wrappers.RSPlayer localRSPlayer1 = new org.rsbot.script.wrappers.RSPlayer(this.ctx, localRSPlayer);
      Point localPoint = this.ctx.calc.tileToScreen(localRSPlayer1.getLocation(), localRSPlayer1.getHeight() / 2);
      if (!this.ctx.calc.pointOnScreen(localPoint)) {
        continue;
      }
      paramGraphics.setColor(Color.RED);
      paramGraphics.fillRect((int)localPoint.getX() - 1, (int)localPoint.getY() - 1, 2, 2);
      String str1 = "" + localRSPlayer1.getName() + " (" + localRSPlayer1.getCombatLevel() + ")";
      paramGraphics.setColor(localRSPlayer1.isMoving() ? Color.GREEN : localRSPlayer1.isInCombat() ? Color.RED : Color.WHITE);
      paramGraphics.drawString(str1, localPoint.x - localFontMetrics.stringWidth(str1) / 2, localPoint.y - localFontMetrics.getHeight() / 2);
      String str2 = localRSPlayer1.getMessage();
      int k = 0;
      if ((localRSPlayer1.getAnimation() != -1) || (localRSPlayer1.getGraphic() != -1) || (localRSPlayer1.getNPCID() != -1)) {
        if (localRSPlayer1.getNPCID() != -1)
          str1 = "(NPC: " + localRSPlayer1.getNPCID() + " | A: " + localRSPlayer1.getAnimation() + " | G: " + localRSPlayer1.getGraphic() + ")";
        else {
          str1 = "(A: " + localRSPlayer1.getAnimation() + " | G: " + localRSPlayer1.getGraphic() + ")";
        }
        paramGraphics.drawString(str1, localPoint.x - localFontMetrics.stringWidth(str1) / 2, localPoint.y - localFontMetrics.getHeight() * 3 / 2);
        k = 1;
      }
      if (str2 != null) {
        paramGraphics.setColor(Color.ORANGE);
        paramGraphics.drawString(str2, localPoint.x - localFontMetrics.stringWidth(str2) / 2, localPoint.y - localFontMetrics.getHeight() * (k != 0 ? 5 : 3) / 2);
      }
    }
  }
}